
import { message } from 'ant-design-vue'
/**
 *
 * @param attr  根据该属性排序
 * @param rev   升序1或降序-1，不填则默认为1
 * @returns 排序
 */
export function isSortBy(attr: any, rev: any) {
  if (rev == undefined) {
    rev = 1;
  } else {
    rev ? 1 : -1;
  }
  return function (a: any, b: any) {
    a = a[attr] as any;
    b = b[attr] as any;

    return (
      (b != "" && b != null && b != "暂不支持" && b != "操作频繁") -
      (a != "" && a != null && a != "暂不支持" && b != "操作频繁") || a - b
    );
  };
}

/**
 * 消息提示
 * @param val  消息类型
 * @param text  提示的消息
 * @param time   提示显示的时间
 */
export function getIsHint(val: any, text: string, time = 0) {
  message.destroy();
  switch (val) {
    case 'info':
      message.info(text);
      break;
    case 'success':
      message.success(text);
      break;
    case 'error':
      message.error(text);
      break;
    case 'warning':
      message.warning(text);
      break;
    case 'loading':
      message.loading(text, time);
      break;
  }
}
